home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / y_n_3.zip / Y-N.ASM < prev    next >
Assembly Source File  |  1987-08-18  |  3KB  |  98 lines

  1.       PAGE     80,132
  2.       TITLE  Y-N  -  Ask Y/N in Batch File
  3. ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  4. ; * Y-N                                   *
  5. ; * Displays command line and then accepts a Y or N, setting ERRORLEVEL   *
  6. ; * to 1 or 0 respectively.  Used only from BATch files.          *
  7. ; * Written by:                               *
  8. ; * R. Lehr, 901 Rye Beach Rd., Huron Ohio  44839              *
  9. ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  10. ; Conversion from ? assembler format to IBM MASM 2.0 format, and trivial  *
  11. ; bug fixes.  8-18-87 Alan Cox                          *
  12. ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  13. ;
  14. PROG      SEGMENT BYTE PUBLIC 'PROG'
  15.       ASSUME  CS:PROG
  16.       ASSUME  DS:PROG
  17.       ORG     100H
  18. MAIN      PROC     NEAR
  19.       JMP     START
  20.  
  21. ;* * * * *
  22. ;*  data *
  23. ;* * * * *
  24. CHAROUT  db  ?
  25.          db  10,13,'$'
  26. EXITCODE db  ?
  27. CMDLN     db  127 dup(?)
  28.          db  '$'
  29.  
  30. ;* * * * *
  31. ;*  code *
  32. ;* * * * *
  33. START:
  34. ;----- Copy command line -----
  35.        mov  ax,129    ; command line at offset 129 int PSP
  36.        mov  si,ax    ; (Program Segment Prefix)
  37.        xor  cx,cx
  38.        mov  cl,ds:[128]            ;Length of command line at offset 128
  39.        lea  DI,CMDLN
  40.        cmp  cx,00    ; if command line length > 0 then
  41.        je   LNEND
  42.        inc  si        ;    skip blank in command line
  43.        dec  cx        ;    and adjust length accordingly
  44.        rep  movsb
  45.        mov  [di], byte ptr ' ' ; append 1 blank
  46.        inc  di
  47. LNEND: mov  [di], byte ptr '$' ; append string terminator
  48.  
  49. ;----- Display command line -----
  50.        mov  AH,09    ; display command line
  51.        lea  DX,CMDLN
  52.        int  21h
  53.  
  54. ;----- Accept Y or N -----
  55. GETYN: nop        ; repeat
  56.        mov  AH,08    ;    accept keyboard input into AL (no echo)
  57.        int  21h
  58.        cmp  AL,00    ;    if chr(0) not ASCII
  59.        jne  UP
  60.        int  21h     ;    get and discard scan code
  61.        jmp  ENDGETYN
  62. UP:
  63.        and  AL,0DFh    ;    convert to upper case
  64. Y:
  65.        cmp  AL,'Y'      ;    if Y
  66.        jne  N
  67.        call DISPLAY    ;    display it
  68.        mov  EXITCODE,1    ;    exitcode = 1
  69.        jmp  RETURN
  70. N:
  71.        cmp  AL,'N'      ;    else if N
  72.        jne  ENDGETYN
  73.        call DISPLAY    ;    display it
  74.        mov  EXITCODE,0    ;    exitcode = 1
  75.        jmp  RETURN
  76. ENDGETYN:
  77.        jmp  GETYN    ; until Y or N
  78.  
  79. RETURN:
  80.        mov  ah,04Ch    ; return with ERRORLEVEL in AL
  81.        mov  al,EXITCODE
  82.        int  21h
  83.  
  84.       MAIN     ENDP
  85.  
  86. ;* * * * * * * *
  87. ;*  procedures *
  88. ;* * * * * * * *
  89. DISPLAY proc
  90.     mov CHAROUT,AL    ; display Y or N and <cr><lf>
  91.     mov AH,09    ;
  92.     lea DX,CHAROUT
  93.     int 21h
  94.     ret
  95. DISPLAY endp
  96. PROG      ENDS
  97.       END     MAIN
  98.